/**
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 *
 *BaseModuleLogDailyStatisticsController
 * 模块操作日志每日统计
 *
 * 修改纪录
 * 2021-12-08 版本：1.0 wangxinhua 创建。
 * @version 版本：1.0
 * @author 作者：wangxinhua
 * 创建日期：2021-12-08
 */

package com.topscomm.base.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.topscomm.base.controller.auto.BaseModuleLogDailyStatisticsControllerAuto;
import com.topscomm.basic.util.SQLAdapter;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * @author: wangxinhua
 * @date: 2021-12-08
 * @description:模块操作日志每日统计Controller
 * @modify:
 */
@RestController
@RequestMapping("base/moduleLogDailyStatistics")
public class BaseModuleLogDailyStatisticsController extends BaseModuleLogDailyStatisticsControllerAuto implements IBaseModuleLogDailyStatisticsController {
	/**
	 * @author: wangxinhua
	 * @date: 2021-12-08
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and name like '%{0}%' ", value);
			}
		}

		if (paraMap.containsKey("qry_user")) {
			String value = paraMap.get("qry_user").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and (operateusercode like '%{0}%' or operateusername like '%{0}%' )", value);
			}
		}

		if (paraMap.containsKey("deptName")) {
			String value = ConvertUtil.convertToString(paraMap.get("deptName"));
			sql.appendSingle(" and exists(select id from cbouser where cboUser.code = BASEMODULELOGDAILYSTATISTICS.operateusercode and exists (select id from cboDept where cboDept.id = cboUser.deptid and cboDept.FULLNAME like '%{0}%')) ", value);
		}

		if (paraMap.containsKey("startDate")) {
			String startDateStr = ConvertUtil.convertToString(paraMap.get("startDate"));
			sql.appendSingle(" and BASEMODULELOGDAILYSTATISTICS.statisticdate >= {0}", SQLAdapter.toDateShort(startDateStr));
		} else {
			DateTime startDate = DateUtil.offsetMonth(new Date(), -1);
			sql.appendSingle(" and BASEMODULELOGDAILYSTATISTICS.statisticdate >= {0}", SQLAdapter.toDateShort(DateUtil.formatDate(startDate)));
		}

		if (paraMap.containsKey("endDate")) {
			String endDateStr = ConvertUtil.convertToString(paraMap.get("endDate"));
			sql.appendSingle(" and BASEMODULELOGDAILYSTATISTICS.statisticdate <= {0}", SQLAdapter.toDateShort(endDateStr));
		} else {
			Date endDate = new Date();
			sql.appendSingle(" and BASEMODULELOGDAILYSTATISTICS.statisticdate <= {0}", SQLAdapter.toDateShort(DateUtil.formatDate(endDate)));
		}

		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and code = '{0}' ", value);
			}
		}

		if (paraMap.containsKey("qry_system")) {
			String value = paraMap.get("qry_system").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and system = '{0}' ", value);
			}
		}

		return sql.toString();
	}

	/**
	 * @author: wangxinhua
	 * @date: 2021-12-08
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}
}

